<?php
namespace common\models;

use Yii;

/**
 * This is the model class for table "UserBond".
 */
class UserbondTimeout extends ActiveRecord {

    /**
     * @name 获取user信息
     * @return \yii\db\ActiveQuery
     */
    public function getUser()
    {
        return $this->hasOne(User::className(), ['id' => 'user_id']);
    }

    /**
     * @name 充值到账，修改用户保证金过期时间
     * @param
     * @return boolean
     */
    public function bondtimeout(){

        if ( ! Yii::$app->userbond->success){
            return false;
        }
        $table = static::tableName();
        $success_at = time();
        $expiry_time = strtotime("+1 year");
        $data = [
            'user_id' => $this->user->id,
            'success_at' =>$success_at,
            'expiry_time' =>$expiry_time,
        ];
        return $this->save();
    }

}